package com.xb.controller;

import com.xb.entity.*;
import com.xb.service.IMedicalRecordService;
import com.xb.service.IOutpatientQueueService;
import com.xb.service.IPatientService;
import com.xb.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * entityController
 * /api/outpatientQueue
 */
@RestController
@RequestMapping("/api/outpatient")
public class OutpatientQueueController {
    @Autowired
    private IOutpatientQueueService outpatientQueueService;
    @Autowired
    private IPatientService patientService;
    @Autowired
    private IMedicalRecordService medicalRecordService;

    @PostMapping("/getCardIdInfo")
    public Result getCardIdInfo(@RequestBody GetCardIdInfoReqVO getCardIdInfoReqVO, HttpSession session) {
        return patientService.selectPatientByPatient(getCardIdInfoReqVO, session);
    }


    @PostMapping("/changePatientInfo")
    public Result changePatientInfo(@RequestBody Patient patient) {
        Result result = new Result();
        if (patientService.updatePatientByCardId(patient)) {
            result.setStatus(Result.RESPONSE_SUCCESS);
        } else {
            result.setMessage("信息提交失败！");
        }
        return result;
    }

    @PostMapping("/getAllOutpatientQueue")
    public Result getAllOutpatientQueue(HttpSession session) {
        Result result = new Result();
        List<OutpatientQueue> outpatientQueues = outpatientQueueService.selectAllOutpatientQueueList(session);
        result.setData(outpatientQueues);
        return result;
    }

    @PostMapping("/ProcessLaterMedicalRecord")
    public Result processLaterMedicalRecord(@RequestBody MedicalRecord medicalRecord, HttpSession session) {
        return medicalRecordService.updateMedicalRecord(medicalRecord, session);
    }

    @PostMapping("/restorePatientInfo")
    public Result restorePatientInfo(int registerId) {
        Result result = new Result();
        Patient patient = patientService.selectPatientByRegisterId(registerId);
        if (patient != null) {
            result.setData(patient);
            result.setStatus(Result.RESPONSE_SUCCESS);
        } else {
            result.setStatus(Result.RESPONSE_FAIL);
            result.setMessage("出错咯!");
        }

        return result;
    }

    @PostMapping("/addMedicalRecord")
    public Result addMedicalRecord(@RequestBody MedicalRecord medicalRecord, HttpSession session) {
        return medicalRecordService.addMedicalRecord(medicalRecord, session);
    }

    @PostMapping("/getMedicalExamination")
    public Result getMedicalExamination(String prescriptionNum){
        return outpatientQueueService.getMedicalExamination(prescriptionNum);
    }



}
